﻿using System.Windows.Forms;

namespace ruscehproj2
{
    public partial class br004 : Form
    {
        byte modeState = 1;
        //bool enabled = false;
        bool isActive = false;
        double angle = 45;
        bool voltageChecked = false;
        bool powered = false;
        bool kris1 = false;
        bool kris2 = false;
        int amp = 0;
        


        public void enable()
        {
            //enabled = true;
        }

        public bool getState()
        {
            return isActive;
        }

        public br004()
        {
            InitializeComponent();
        }

        private void br004_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Hide();
            }
        }

        private void br004_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (isActive) FormManager.hlp.setHelpId("24");
            FormManager.hlp.Hide();
        }

        private void br004_Load(object sender, System.EventArgs e)
        {
            if (powered)
            {
            }
            if (FormManager.hlp.helpEnabled())
            {
                if (FormManager.bv9kit1.getState())
                {
                    if (isActive)
                    {
                        FormManager.hlp.setHelpId("end");
                    }
                    else FormManager.hlp.setHelpId("19");
                    FormManager.hlp.hlpRefresh();
                }
                else
                {
                    FormManager.hlp.notSoFast();
                }



                FormManager.hlp.Show();
            }
        }

        private void mode_Click(object sender, System.EventArgs e)
        {
            if (powered)
            {
                modeState++;
                if (modeState > 6)
                {
                    voltageChecked = true;
                    modeState = 1;

                }
                if (voltageChecked)
                {
                    FormManager.hlp.setHelpId("21");
                    if (modeState == 1 || modeState == 1)
                    {
                        FormManager.hlp.setHelpId("22");
                    }
                    else if (kris1 && kris2 && voltageChecked)
                    {
                        FormManager.hlp.setHelpId("23");
                    }
                }
                switch (modeState)
                {
                    case 1: mode.BackgroundImage = Resources.set3; angle = 45; break;
                    case 2: mode.BackgroundImage = Resources.set4; angle = 45; break;
                    case 3: mode.BackgroundImage = Resources.set5; angle = 45; break;
                    case 4: mode.BackgroundImage = Resources.set6; angle = 100; break;
                    case 5: mode.BackgroundImage = Resources.set7; angle = 92; break;
                    case 6: mode.BackgroundImage = Resources.set8; angle = 80; break;
                }
                FormManager.hlp.hlpRefresh();
            }
        }

        private void vkl_Click(object sender, System.EventArgs e)
        {
            powered = true;
            FormManager.hlp.setHelpId("20");
            FormManager.hlp.hlpRefresh();
        }

        private void krist1_Click(object sender, System.EventArgs e)
        {
            if (modeState == 1)
            {
                kris1 = true;
            }
            if (kris1 && kris2)
            {
                FormManager.hlp.setHelpId("23");
                FormManager.hlp.hlpRefresh();
            }
        }

        private void krist2_Click(object sender, System.EventArgs e)
        {
            if (modeState == 2)
            {
                kris2 = true;
                if (kris1 && kris2)
                {
                    FormManager.hlp.setHelpId("23");
                    FormManager.hlp.hlpRefresh();
                }
            }
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            if (modeState == 3 && kris1 && kris2 && powered)
            {
                amp++;
                if (amp > 2 && amp < 6)
                {
                    pictureBox1.BackgroundImage = Resources.grLight;
                    pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
                    pictureBox2.BackgroundImage = Resources.null256;
                    pictureBox2.BackgroundImageLayout = ImageLayout.Stretch;
                    FormManager.hlp.setHelpId("end");
                    FormManager.hlp.hlpRefresh();
                    isActive = true;
                }
                else
                {
                    pictureBox2.BackgroundImage = Resources.grLight;
                    pictureBox2.BackgroundImageLayout = ImageLayout.Stretch;
                    pictureBox1.BackgroundImage = Resources.null256;
                    pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
                    FormManager.hlp.setHelpId("23");
                    FormManager.hlp.hlpRefresh();
                    isActive = false;
                }
                if (amp > 10) amp = 0;
            }
        }
    }
}
